package com.jyt.CollectionServiceImp;

import org.junit.Test;

import com.jyt.baseUtil.RiZhiServlet;
import com.jyt.mockClientMsgBase.MockClientMsgBase_RNpay;


public class MockClientMsg_TD1001 extends MockClientMsgBase_RNpay {

	public static String TRAN_CODE = "TD1001";

	/**
	 * ���п���β�ţ� 1 ����һ�������� 2���״�����
	 * 
	 * @throws Exception
	 */
	@Test
	public Infozhuangtai testTC1001_OK(String uid, String tcustNo,
			String tbankCardNo, String tidCardNo, String tmobile, String tname,
			String ttranAmount) throws Exception {
		String custNo = tcustNo;
		String orderId = MockClientMsgBase_RNpay.getOrderId();// ֧�����׵���ˮ�ţ���ƽ̨�Ķ�������
		// System.out.println(orderId);

		String bankCardNo = tbankCardNo;
		String idCardNo = tidCardNo;
		String mobile = tmobile;
		String name = tname;
		String tranAmount = ttranAmount;

		String xml = getTD1001Xml(custNo, orderId, bankCardNo, idCardNo,
				mobile, name, tranAmount);
		System.out.println("���ͱ���" + xml);
		String mac = signMsg(xml);// ��ǩ�����̻���˽Կ���м�ǩ
		String respMsg = sendMsg(xml, mac);// ������Ӧ����
		String respCode = getMsgRespCode(respMsg);
		String tran_flowid = getMsgtran_flowid(respMsg);
		String resp_desc = getMsgresp_desc(respMsg);
		System.out.println("��ע��" + resp_desc);
		System.out.println("������ˮ�ţ�" + tran_flowid);
		System.out.println("��Ӧ����" + respMsg);
		System.out.println("������" + respCode);

		Infozhuangtai infozhuangtai = new Infozhuangtai();
		infozhuangtai.setOrderId(orderId);
		infozhuangtai.setRespCode(respCode);
		infozhuangtai.setResp_desc(resp_desc);
		infozhuangtai.setTran_flowid(tran_flowid);

		double lsje = Double.parseDouble(tranAmount);

		new RiZhiServlet().zhifurizhi(lsje, "�״�֧����", uid, tran_flowid,
				"TD1001", "null", respCode, resp_desc);

		return infozhuangtai;
	}

	public String getTD1001Xml(String custNo, String orderId,
			String bankCardNo, String idCardNo, String mobile, String name,
			String tranAmount) {
		StringBuffer xml = new StringBuffer();
		xml.append(getMsgHeadXml(TRAN_CODE));
		xml.append("<body><cust_no>").append(custNo).append("</cust_no>");
		xml.append("<order_id>").append(orderId).append("</order_id>");
		xml.append("<bank_card_no>").append(bankCardNo)
				.append("</bank_card_no>");
		xml.append("<id_card_no>").append(idCardNo).append("</id_card_no>");
		xml.append("<mobile>").append(mobile).append("</mobile>");
		xml.append("<name>").append(name).append("</name>");
		xml.append("<tran_amount>").append(tranAmount).append("</tran_amount>");
		xml.append("</body></message>");
		return xml.toString();
	}
}
